﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace CPPEI.WebApiTool
{
    public class WebApiRefBuilder
    {
        StringBuilder _stringBuilder = new StringBuilder();

        List<Assembly> _assemblyList;

        public WebApiRefBuilder(List<Assembly> assemblyList)
        {
            _assemblyList = assemblyList;
        }

        public void Build(string filePath)
        {
            XmlDocument xDoc = new XmlDocument();

            XmlElement xWebApiList = xDoc.CreateElement("WebApi-List");

            foreach (var assembly in _assemblyList)
            {
                XmlElement xWebApi = xDoc.CreateElement("WebApi");

                XmlAttribute xattrAssembly = xDoc.CreateAttribute("Assembly");
                xattrAssembly.Value = assembly.FullName;
                xWebApi.Attributes.Append(xattrAssembly);

                xWebApiList.AppendChild(xWebApi);
            }
            xDoc.AppendChild(xWebApiList);

            xDoc.Save(filePath);
        }
    }
}
